package lexicalUnit;

import chalmersbot.Absyn.ISub;
import chalmersbot.Absyn.ISubIsSub;
import chalmersbot.Absyn.IPhrase.Visitor;
import chalmersbot.Absyn.ISubNr;

public class CheckIPhrase implements Visitor<String, Environ> {

	@Override
	public String visit(ISub p, Environ env) {
		env.resetFlag();
		String comp = p.subject_.accept(new CheckSubject(), env);
		if (!comp.startsWith("in"))
			comp = "in " + comp; 
		return env.getSentence() + " " + comp;
	}

	@Override
	public String visit(ISubIsSub p, Environ env) {
		env.resetFlag();
		String comp = p.subject_2.accept(new CheckSubject(), env);
		if (!comp.startsWith("in"))
			comp = "in " + comp;
		return env.getSentence() + " " + comp;
	}

	@Override
	public String visit(ISubNr p, Environ env) {
		env.resetFlag();
		String period = p.numberrule_.accept(new CheckNumberRule(), env);
		if (period.compareTo("one")==0)
			env.setPeriod(Integer.toString(1));
		else if (period.compareTo("two")==0)
			env.setPeriod(Integer.toString(2));
		else if (period.compareTo("three")==0)
			env.setPeriod(Integer.toString(3));
		else if (period.compareTo("four")==0)
			env.setPeriod(Integer.toString(4));
		else
			env.setPeriod(period);
		return env.getSentence() + " in period " + period;
	}

}
